package com.liang.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liang.entity.CActive;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 李昂
 * @since 2020-11-30
 */
public interface CActiveMapper extends BaseMapper<CActive> {

    //查看活动报名人
    @Select("select b.name as username ,b.sno from aid_id a , c_user b where a.aid=#{id} and b.id=a.id")
    List<CActive> getUsers(@Param("id") int id);


    //查看活动列表
    @Select("select aid,name,address,starttime,endtime,type,host,image from c_active")
    List<CActive> getActives();

    //获取详情页面
    @Select("select detail from c_active where aid=#{id}")
    String getDetail(@Param("id") int id);

    //参加活动
    @Insert("insert into aid_id values(#{aid},#{id})")
    boolean takeInActive(@Param("aid") int aid, @Param("id") String id);

    //参加人数，判断自己是否参加
    @Select("select aid,count(*) AS count,sum(id=#{id}) as extis from aid_id GROUP BY aid")
    List<CActive> takeActiveCount(@Param("id") String id);

    //取消参加活动
    @Delete("delete from aid_id where id=#{id} and aid=#{aid}")
    boolean  CancelActive(@Param("id") String id,@Param("aid") int aid);

}
